import pageination from '../../components/pageination/pageination.vue'
import urls from "../../common/js/api_url_array";
export default {
	data() {
		return {
			//数据
			total: 0, //总条数
			page: 1, //当前页
			size: 10,//每页显示条数
      classId: '',//班级id
			modelShow: false,//修改
			uploadNum: 0,
			FileUpload: [],
      search: '', //搜索信息
      classList: [], //班级列表
      studentCurriculum: {},
      optionStatus: 0, //结业证书操作状态（0：上传；1：修改）
      graduation: {},
      graduationList: [] //结业列表
		}
	},
	components: {
		pageination
	},
	created() { //调用方法
    //初始化证书分页信息
    //this.searchTodo();
    this.searchAllClass();
	},
	mounted() {
	},
	methods: { //写函数方法
		//页码切换执行方法
		pageFn: function(val, pid) {
			this.page = parseInt(val);
			//此处调列表数据接口
			this.searchTodo(); //查询新闻
		},
		/**返回子组件用户选择的一页显示条数**/
		obtainChild: function(data) {
			this.row = data;
		},
		//打开模态框
		openModal: function(graduation,type) {
		  this.optionStatus = type;
      this.graduation = graduation;
      this.FileUpload = [this.getFileName(graduation.graduationCertificateUrl)];
      this.modelShow = true;
      //this.getData(id);
		},
		//关闭模态框
		closeModel: function() {
			this.modelShow = false;
		},
		touchOffIdInput(n) {
			this.uploadNum = n;
			if(n == 1) {
				$("#handIdFront").click();
			}
		},
    //预览
    preview: function(url,msg) {
      if (url == null || url == "") {
        if (msg == null || msg == "") {
          msg = "附件";
        }
        layer.msg("暂无" + msg + "！");
      } else {
        window.open(this.urls.baseUrl + url);
      }
    },
		/**文件上传js**/
		idFrontImg: function(event) {
      		let that = this;
		 	var file = event.currentTarget.files[0];
		 	if (!that.fileGlobalFilter(file)) {
		 		return;
		 	}
		 	let formData = new FormData();
		 	formData.append('fileNames', file);
		 	let config = {
			 	headers: {
			 		'Content-Type': 'multipart/form-data;boundary = ' + new Date().getTime()
			 	}
		 	};
		 	var loadIndex = layer.load(1);
		 	that.$post(
		 		that.urls.upload,
		 		formData,
		 		config
		 	)
		 	.then(function(res) {
		 		if (res.success) {
		 			let fileInfo = res.data[0];
		 			that.FileUpload = [that.getFileName(fileInfo.url)];
		 			that.graduation.graduationCertificateUrl = fileInfo.url;
		 		}
		 		layer.close(loadIndex);
		 	})
		 	.catch(function(error) {
		 		layer.close(loadIndex);
		 	});
		},
    //获取单个数据
    getData: function(id) {
		  if (id != null) {
        let that = this;
        that.$post(
          that.urls.getStudentCurriculum,
          {"id": id}
        )
        .then(function(res) {
          if(res.success) {
            that.studentCurriculum = res.data;
          }
        })
      }
    },
    //获取所有班级信息
    searchAllClass: function() {
      let that = this;
      that.$post(
        that.urls.classList,
        {"pageNum": 0,"pageSize": 999}
      )
        .then(function(res) {
          if(res.success) {
            that.classList = res.pageInfo.list;
          }
        })
    },
    //搜索数据列表
    searchTodo: function() {
      let that = this;
      that.$post(
        that.urls.getGraduationPageInfo,
        {"pageNum": that.page,"pageSize": that.size,"classId": that.classId,"search": that.search}
      )
      .then(function(res) {
        if(res.success) {
          that.graduationList = res.pageInfo.list;
          that.total = res.pageInfo.total;
          that.page = res.pageInfo.pageNum;
        }
      })
    },
    //导出数据
    exportData: function() {
		  window.location.href = this.urls.exportGraduation + "?classId=" + this.classId + "&search=" + this.search;
    },
    //根据ids导出数据
    exportByIds: function() {
      //获取所有选中的id
      let ids = [];
      let objs = $("input[name='ids']:checked");
      for (let i = 0,len = objs.length;i < len;i++) {
        ids.push($(objs[i]).val());
      }
      if (ids.length == 0) {
        layer.msg("请选择导出的结业信息！", {
          time: 3000, //3s后自动关闭
        });
        return;
      }
		  window.location.href = this.urls.exportByIds + "?ids=" + ids;
    },
    //修改结业信息
    updateData: function() {
      let that = this;
      let data = this.combinationFormObject($("#graduationForm")[0]);
      if (data.graduationCertificateUrl == null || data.graduationCertificateUrl == '') {
        layer.msg("请上传结业证书", {
          time: 3000, //3s后自动关闭
        });
        return;
      }
      //初始化成果分页信息
      that.$post(
        that.urls.updateGraduation,
        data
      )
      .then(function(res) {
        let msg = "";
        if(res.success) {
          msg = '证书保存成功！';
          //重新渲染数据
          that.searchTodo();
          that.modelShow = false;
        } else {
          msg = '证书保存失败！';
        }
        layer.msg(msg, {
          time: 3000, //3s后自动关闭
        });
      })
    },
	}
}
